﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Sgr.Admin.WebHost.Infrastructure.Migrations.Upms
{
    /// <inheritdoc />
    public partial class InitialUpmsSchema : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AlterDatabase()
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "upms_department",
                columns: table => new
                {
                    sgr_id = table.Column<long>(type: "bigint", nullable: false, comment: "主键"),
                    m_code = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: false, comment: "部门编码")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_name = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: false, comment: "部门名称")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_ordernumber = table.Column<int>(type: "int", nullable: false, comment: "组织排序号"),
                    m_manageruserid = table.Column<long>(type: "bigint", nullable: true, comment: "主管用户Id"),
                    m_leader = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: true, comment: "负责人(冗余)")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_phone = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: true, comment: "联系电话(冗余)")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_email = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: true, comment: "联系邮箱(冗余)")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_remarks = table.Column<string>(type: "varchar(500)", maxLength: 500, nullable: true, comment: "描述")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_state = table.Column<int>(type: "int", nullable: false, comment: "部门状态"),
                    sgr_parentid = table.Column<long>(type: "bigint", nullable: false, comment: "上级节点Id"),
                    sgr_nodepath = table.Column<string>(type: "varchar(255)", maxLength: 255, nullable: false, comment: "树节点层次目录")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    sgr_rowversion = table.Column<long>(type: "bigint", nullable: false, comment: "行版本"),
                    sgr_orgid = table.Column<long>(type: "bigint", nullable: false, comment: "所在组织ID"),
                    sgr_creatoruserid = table.Column<long>(type: "bigint", nullable: false, comment: "创建的用户ID"),
                    sgr_creationtime = table.Column<DateTime>(type: "datetime(6)", nullable: false, comment: "创建时间"),
                    sgr_lastmodifieruserid = table.Column<long>(type: "bigint", nullable: false, comment: "修改的用户ID"),
                    sgr_lastmodificationtime = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: "修改时间")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_upms_department", x => x.sgr_id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "upms_duty",
                columns: table => new
                {
                    sgr_id = table.Column<long>(type: "bigint", nullable: false, comment: "主键"),
                    m_code = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: false, comment: "职务编码")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_name = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: false, comment: "职务名称")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_ordernumber = table.Column<int>(type: "int", nullable: false, comment: "排序号"),
                    m_remarks = table.Column<string>(type: "varchar(500)", maxLength: 500, nullable: true, comment: "职务备注")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_state = table.Column<int>(type: "int", nullable: false, comment: "职务状态"),
                    sgr_rowversion = table.Column<long>(type: "bigint", nullable: false, comment: "行版本"),
                    sgr_orgid = table.Column<long>(type: "bigint", nullable: false, comment: "所在组织ID"),
                    sgr_creatoruserid = table.Column<long>(type: "bigint", nullable: false, comment: "创建的用户ID"),
                    sgr_creationtime = table.Column<DateTime>(type: "datetime(6)", nullable: false, comment: "创建时间"),
                    sgr_lastmodifieruserid = table.Column<long>(type: "bigint", nullable: false, comment: "修改的用户ID"),
                    sgr_lastmodificationtime = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: "修改时间")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_upms_duty", x => x.sgr_id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "upms_loglogin",
                columns: table => new
                {
                    sgr_id = table.Column<long>(type: "bigint", nullable: false, comment: "主键"),
                    m_loginname = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: false, comment: "登录账号")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_displayname = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: true, comment: "用户姓名")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_logintime = table.Column<DateTime>(type: "datetime(6)", nullable: false, comment: "登录时间"),
                    m_ipaddress = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: true, comment: "登录Ip地址")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_location = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: true, comment: "登录地点")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_loginway = table.Column<int>(type: "int", nullable: false, comment: "登录途径"),
                    m_loginprovider = table.Column<string>(type: "varchar(500)", maxLength: 500, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_providerkey = table.Column<string>(type: "varchar(500)", maxLength: 500, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_providerdisplayname = table.Column<string>(type: "varchar(500)", maxLength: 500, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_clientbrowser = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: true, comment: "客户端浏览器")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_clientos = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: true, comment: "客户端系统")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_status = table.Column<bool>(type: "tinyint(1)", nullable: false, comment: "登录状态"),
                    m_remark = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: true, comment: "登录描述")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    sgr_orgid = table.Column<long>(type: "bigint", nullable: false, comment: "所在组织ID"),
                    sgr_creatoruserid = table.Column<long>(type: "bigint", nullable: false, comment: "创建的用户ID"),
                    sgr_creationtime = table.Column<DateTime>(type: "datetime(6)", nullable: false, comment: "创建时间")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_upms_loglogin", x => x.sgr_id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "upms_menus",
                columns: table => new
                {
                    sgr_id = table.Column<long>(type: "bigint", nullable: false, comment: "主键"),
                    m_name = table.Column<string>(type: "varchar(255)", maxLength: 255, nullable: false, comment: "菜单名称")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_code = table.Column<string>(type: "varchar(255)", maxLength: 255, nullable: false, comment: "菜单编码")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_icon = table.Column<string>(type: "varchar(255)", maxLength: 255, nullable: true, comment: "菜单图标")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_routename = table.Column<string>(type: "varchar(255)", maxLength: 255, nullable: true, comment: "路由名称")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_routepath = table.Column<string>(type: "varchar(255)", maxLength: 255, nullable: true, comment: "路由路径")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_componentpath = table.Column<string>(type: "varchar(255)", maxLength: 255, nullable: true, comment: "组件路径")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_redirectpath = table.Column<string>(type: "varchar(255)", maxLength: 255, nullable: true, comment: "重定向路径")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_order = table.Column<int>(type: "int", nullable: false, defaultValue: 0, comment: "排序号"),
                    m_permission = table.Column<string>(type: "varchar(255)", maxLength: 255, nullable: true, comment: "权限标识")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_type = table.Column<int>(type: "int", maxLength: 20, nullable: false, comment: "菜单类型：Directory-目录，Menu-菜单，Button-按钮"),
                    m_isactive = table.Column<bool>(type: "tinyint(1)", nullable: false, defaultValue: true, comment: "是否激活：true-是，false-否"),
                    m_isdeactivatebyparent = table.Column<bool>(type: "tinyint(1)", nullable: false, defaultValue: false, comment: "是否因父菜单停用而停用：true-是，false-否"),
                    m_description = table.Column<string>(type: "varchar(500)", maxLength: 500, nullable: true, comment: "菜单描述")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_externallink = table.Column<bool>(type: "tinyint(1)", nullable: false, defaultValue: false, comment: "是否外部链接：true-是，false-否"),
                    m_hidden = table.Column<bool>(type: "tinyint(1)", nullable: false, defaultValue: false, comment: "是否隐藏：true-是，false-否"),
                    m_keepalive = table.Column<bool>(type: "tinyint(1)", nullable: false, defaultValue: false, comment: "是否缓存：true-是，false-否"),
                    m_target = table.Column<int>(type: "int", maxLength: 20, nullable: true, comment: "目标窗口：Self-当前窗口，Blank-新窗口"),
                    m_affix = table.Column<bool>(type: "tinyint(1)", nullable: false, defaultValue: false, comment: "是否固定：true-是，false-否"),
                    m_sgr_parentid = table.Column<long>(type: "bigint", nullable: false, defaultValue: 0L, comment: "父级菜单ID"),
                    m_sgr_nodepath = table.Column<string>(type: "varchar(1000)", maxLength: 1000, nullable: false, comment: "节点路径")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    sgr_rowversion = table.Column<long>(type: "bigint", nullable: false, comment: "行版本"),
                    sgr_creatoruserid = table.Column<long>(type: "bigint", nullable: false, comment: "创建的用户ID"),
                    sgr_creationtime = table.Column<DateTime>(type: "datetime(6)", nullable: false, comment: "创建时间"),
                    sgr_lastmodifieruserid = table.Column<long>(type: "bigint", nullable: false, comment: "修改的用户ID"),
                    sgr_lastmodificationtime = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: "修改时间")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_upms_menus", x => x.sgr_id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "upms_org_invitations",
                columns: table => new
                {
                    sgr_id = table.Column<long>(type: "bigint", nullable: false, comment: "主键"),
                    OrganizationId = table.Column<long>(type: "bigint", nullable: false),
                    InvitationCode = table.Column<string>(type: "varchar(20)", maxLength: 20, nullable: false)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    ExpireTime = table.Column<DateTime>(type: "datetime(6)", nullable: false),
                    UsageLimit = table.Column<int>(type: "int", nullable: false, defaultValue: -1),
                    UsedCount = table.Column<int>(type: "int", nullable: false, defaultValue: 0),
                    Description = table.Column<string>(type: "varchar(500)", maxLength: 500, nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    State = table.Column<int>(type: "int", nullable: false),
                    sgr_rowversion = table.Column<long>(type: "bigint", nullable: false, comment: "行版本"),
                    sgr_creatoruserid = table.Column<long>(type: "bigint", nullable: false, comment: "创建的用户ID"),
                    sgr_creationtime = table.Column<DateTime>(type: "datetime(6)", nullable: false, comment: "创建时间"),
                    sgr_lastmodifieruserid = table.Column<long>(type: "bigint", nullable: false, comment: "修改的用户ID"),
                    sgr_lastmodificationtime = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: "修改时间")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_upms_org_invitations", x => x.sgr_id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "upms_organization",
                columns: table => new
                {
                    sgr_id = table.Column<long>(type: "bigint", nullable: false, comment: "主键"),
                    m_name = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: false, comment: "组织机构名称")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_staffsizecode = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: false, comment: "人员规模编码")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_remarks = table.Column<string>(type: "varchar(1000)", maxLength: 1000, nullable: true, comment: "描述")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_logourl = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: true, comment: "Logo地址")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_code = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: false, comment: "组织机构编码")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_identificationcode = table.Column<string>(type: "varchar(10)", maxLength: 10, nullable: false, comment: "组织机构识别码")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_orgtypecode = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: false, comment: "组织机构类型编码")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_areacode = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: false, comment: "所属行政区划编码")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_leader = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: true, comment: "机构负责人")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_phone = table.Column<string>(type: "varchar(30)", maxLength: 30, nullable: true, comment: "联系电话")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_email = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: true, comment: "联系邮箱")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_address = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: true, comment: "所在地址")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_businesslicensepath = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: true, comment: "营业执照路径")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_confirmed = table.Column<int>(type: "int", nullable: false, comment: "组织机构认证状态"),
                    m_ordernumber = table.Column<int>(type: "int", nullable: false, comment: "组织机构排序号"),
                    m_state = table.Column<int>(type: "int", nullable: false, comment: "组织机构状态"),
                    m_lastcancellationtime = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: "注销时间"),
                    sgr_parentid = table.Column<long>(type: "bigint", nullable: false, comment: "上级节点Id"),
                    sgr_nodepath = table.Column<string>(type: "varchar(255)", maxLength: 255, nullable: false, comment: "树节点层次目录")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    sgr_rowversion = table.Column<long>(type: "bigint", nullable: false, comment: "行版本"),
                    sgr_extensiondata = table.Column<string>(type: "json", nullable: true, comment: "扩展对象/实体(JSON)")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    sgr_creatoruserid = table.Column<long>(type: "bigint", nullable: false, comment: "创建的用户ID"),
                    sgr_creationtime = table.Column<DateTime>(type: "datetime(6)", nullable: false, comment: "创建时间"),
                    sgr_lastmodifieruserid = table.Column<long>(type: "bigint", nullable: false, comment: "修改的用户ID"),
                    sgr_lastmodificationtime = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: "修改时间"),
                    sgr_deleteruserid = table.Column<long>(type: "bigint", nullable: false, comment: "删除的用户ID"),
                    sgr_deletiontime = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: "删除时间"),
                    sgr_isdeleted = table.Column<bool>(type: "tinyint(1)", nullable: false, comment: "是否已经被软删除")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_upms_organization", x => x.sgr_id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "upms_role",
                columns: table => new
                {
                    sgr_id = table.Column<long>(type: "bigint", nullable: false, comment: "主键"),
                    m_code = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: false, comment: "角色编码")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_rolename = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: false, comment: "角色名称")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_ordernumber = table.Column<int>(type: "int", nullable: false, comment: "排序号"),
                    m_remarks = table.Column<string>(type: "varchar(500)", maxLength: 500, nullable: true, comment: "备注")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_state = table.Column<int>(type: "int", nullable: false, comment: "状态"),
                    sgr_rowversion = table.Column<long>(type: "bigint", nullable: false, comment: "行版本"),
                    sgr_orgid = table.Column<long>(type: "bigint", nullable: false, comment: "所在组织ID"),
                    sgr_creatoruserid = table.Column<long>(type: "bigint", nullable: false, comment: "创建的用户ID"),
                    sgr_creationtime = table.Column<DateTime>(type: "datetime(6)", nullable: false, comment: "创建时间"),
                    sgr_lastmodifieruserid = table.Column<long>(type: "bigint", nullable: false, comment: "修改的用户ID"),
                    sgr_lastmodificationtime = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: "修改时间")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_upms_role", x => x.sgr_id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "upms_temporary_tokens",
                columns: table => new
                {
                    sgr_id = table.Column<long>(type: "bigint", nullable: false, comment: "主键"),
                    Code = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: false, comment: "令牌编码")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    TokenType = table.Column<int>(type: "int", nullable: false, comment: "令牌类型"),
                    Content = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: true, comment: "令牌内容")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    DeviceFingerprint = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: true, comment: "关联的设备指纹")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    UserId = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: true, comment: "关联的用户Id")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    CreationTime = table.Column<DateTime>(type: "datetime(6)", nullable: false, comment: "创建时间"),
                    ExpirationTime = table.Column<DateTime>(type: "datetime(6)", nullable: false, comment: "过期时间"),
                    IsUsed = table.Column<bool>(type: "tinyint(1)", nullable: false, comment: "是否已使用")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_upms_temporary_tokens", x => x.sgr_id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "upms_user",
                columns: table => new
                {
                    sgr_id = table.Column<long>(type: "bigint", nullable: false, comment: "主键"),
                    m_username = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: true, comment: "用户姓名")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_gender = table.Column<int>(type: "int", nullable: false, comment: "性别"),
                    m_qq = table.Column<string>(type: "varchar(20)", maxLength: 20, nullable: true, comment: "用户QQ号码")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_birthday = table.Column<DateOnly>(type: "date", nullable: true, comment: "出生日期"),
                    m_loginname = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: false, comment: "登录名称")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_loginpassword = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: false, comment: "登录密码")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_userphone = table.Column<string>(type: "varchar(30)", maxLength: 30, nullable: true, comment: "用户绑定的手机号码")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_isphoneverified = table.Column<bool>(type: "tinyint(1)", nullable: false, defaultValue: false, comment: "手机号是否已验证"),
                    m_useremail = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: true, comment: "用户邮箱地址")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_isemailverified = table.Column<bool>(type: "tinyint(1)", nullable: false, defaultValue: false, comment: "邮箱是否已验证"),
                    m_issuperadmin = table.Column<bool>(type: "tinyint(1)", nullable: false),
                    m_state = table.Column<int>(type: "int", nullable: false, comment: "状态"),
                    m_mainauthenticationtype = table.Column<int>(type: "int", nullable: false, defaultValue: 0, comment: "主要身份验证类型"),
                    m_wechatopenid = table.Column<string>(type: "varchar(255)", maxLength: 255, nullable: true, comment: "微信OpenId")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_wechatunionid = table.Column<string>(type: "varchar(255)", maxLength: 255, nullable: true, comment: "微信UnionId")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_authenticatorkey = table.Column<string>(type: "varchar(255)", maxLength: 255, nullable: true, comment: "双因素认证密钥")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_twofactorenabled = table.Column<bool>(type: "tinyint(1)", nullable: false, defaultValue: false, comment: "是否启用双因素认证"),
                    m_firstlogintime = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: "首次登录时间"),
                    m_lastlogintime = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: "最近一次登录时间"),
                    m_loginsuccesscount = table.Column<int>(type: "int", nullable: false, comment: "登录成功次数"),
                    m_failedloginattempts = table.Column<int>(type: "int", nullable: false, comment: "连续登录失败次数"),
                    m_cannotloginuntilutc = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: "禁止登录的截止时间"),
                    m_departmentid = table.Column<long>(type: "bigint", nullable: true, comment: "所属部门Id"),
                    m_departmentname = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: false, comment: "所属部门名称")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_primarydutyid = table.Column<long>(type: "bigint", nullable: true, comment: "首要的岗位Id"),
                    m_primarydeptname = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: false, comment: "首要的岗位名称")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_superioruserid = table.Column<long>(type: "bigint", nullable: true, comment: "直接上级用户Id"),
                    m_superiorusername = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: false, comment: "直接上级用户名称")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    sgr_rowversion = table.Column<long>(type: "bigint", nullable: false, comment: "行版本"),
                    sgr_orgid = table.Column<long>(type: "bigint", nullable: false, comment: "所在组织ID"),
                    sgr_creatoruserid = table.Column<long>(type: "bigint", nullable: false, comment: "创建的用户ID"),
                    sgr_creationtime = table.Column<DateTime>(type: "datetime(6)", nullable: false, comment: "创建时间"),
                    sgr_lastmodifieruserid = table.Column<long>(type: "bigint", nullable: false, comment: "修改的用户ID"),
                    sgr_lastmodificationtime = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: "修改时间"),
                    sgr_deleteruserid = table.Column<long>(type: "bigint", nullable: false, comment: "删除的用户ID"),
                    sgr_deletiontime = table.Column<DateTime>(type: "datetime(6)", nullable: true, comment: "删除时间"),
                    sgr_isdeleted = table.Column<bool>(type: "tinyint(1)", nullable: false, comment: "是否已经被软删除")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_upms_user", x => x.sgr_id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "upms_user_refreshtoken",
                columns: table => new
                {
                    sgr_id = table.Column<long>(type: "bigint", nullable: false, comment: "主键"),
                    m_token = table.Column<string>(type: "varchar(100)", maxLength: 100, nullable: false, comment: "令牌内容")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_expires = table.Column<DateTime>(type: "datetime(6)", nullable: false, comment: "失效时间"),
                    m_userid = table.Column<long>(type: "bigint", nullable: false, comment: "用户标识"),
                    m_bindingmark = table.Column<string>(type: "varchar(255)", maxLength: 255, nullable: false, comment: "绑定的标记")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_createtime = table.Column<DateTime>(type: "datetime(6)", nullable: false, comment: "刷新令牌的创建时间")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_upms_user_refreshtoken", x => x.sgr_id);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "upms_role_resource",
                columns: table => new
                {
                    sgr_id = table.Column<string>(type: "varchar(255)", nullable: false, comment: "主键")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_resourcecode = table.Column<string>(type: "varchar(200)", maxLength: 200, nullable: false, comment: "资源标识")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_resourcetype = table.Column<int>(type: "int", nullable: false, comment: "资源类型"),
                    m_roleid = table.Column<long>(type: "bigint", nullable: false, comment: "角色标识")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_upms_role_resource", x => x.sgr_id);
                    table.ForeignKey(
                        name: "FK_upms_role_resource_upms_role_m_roleid",
                        column: x => x.m_roleid,
                        principalTable: "upms_role",
                        principalColumn: "sgr_id",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "upms_user_duty",
                columns: table => new
                {
                    sgr_id = table.Column<string>(type: "varchar(255)", nullable: false, comment: "主键")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_dutyid = table.Column<long>(type: "bigint", nullable: false, comment: "岗位标识"),
                    m_userid = table.Column<long>(type: "bigint", nullable: false, comment: "用户标识")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_upms_user_duty", x => x.sgr_id);
                    table.ForeignKey(
                        name: "FK_upms_user_duty_upms_user_m_userid",
                        column: x => x.m_userid,
                        principalTable: "upms_user",
                        principalColumn: "sgr_id",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateTable(
                name: "upms_user_role",
                columns: table => new
                {
                    sgr_id = table.Column<string>(type: "varchar(255)", nullable: false, comment: "主键")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    m_roleid = table.Column<long>(type: "bigint", nullable: false, comment: "角色标识"),
                    m_userid = table.Column<long>(type: "bigint", nullable: false, comment: "用户标识")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_upms_user_role", x => x.sgr_id);
                    table.ForeignKey(
                        name: "FK_upms_user_role_upms_user_m_userid",
                        column: x => x.m_userid,
                        principalTable: "upms_user",
                        principalColumn: "sgr_id",
                        onDelete: ReferentialAction.Cascade);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_Department_Id_Name",
                table: "upms_department",
                columns: new[] { "sgr_id", "m_name" });

            migrationBuilder.CreateIndex(
                name: "IX_upms_department_sgr_orgid",
                table: "upms_department",
                column: "sgr_orgid");

            migrationBuilder.CreateIndex(
                name: "IX_Duty_Id_Name",
                table: "upms_duty",
                columns: new[] { "sgr_id", "m_name" });

            migrationBuilder.CreateIndex(
                name: "IX_upms_duty_sgr_orgid",
                table: "upms_duty",
                column: "sgr_orgid");

            migrationBuilder.CreateIndex(
                name: "IX_LogLogin_LoginTime_OrgId",
                table: "upms_loglogin",
                columns: new[] { "m_logintime", "sgr_orgid" });

            migrationBuilder.CreateIndex(
                name: "IX_upms_menus_m_sgr_parentid",
                table: "upms_menus",
                column: "m_sgr_parentid");

            migrationBuilder.CreateIndex(
                name: "UK_Menu_ParentId_Name",
                table: "upms_menus",
                columns: new[] { "m_sgr_parentid", "m_name" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "UK_Menu_RouteName",
                table: "upms_menus",
                column: "m_routename",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_upms_org_invitations_InvitationCode",
                table: "upms_org_invitations",
                column: "InvitationCode",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_upms_org_invitations_OrganizationId",
                table: "upms_org_invitations",
                column: "OrganizationId");

            migrationBuilder.CreateIndex(
                name: "IX_upms_organization_m_code",
                table: "upms_organization",
                column: "m_code",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_upms_organization_m_identificationcode",
                table: "upms_organization",
                column: "m_identificationcode",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_upms_organization_m_ordernumber",
                table: "upms_organization",
                column: "m_ordernumber");

            migrationBuilder.CreateIndex(
                name: "IX_upms_organization_sgr_parentid",
                table: "upms_organization",
                column: "sgr_parentid");

            migrationBuilder.CreateIndex(
                name: "IX_upms_role_m_rolename",
                table: "upms_role",
                column: "m_rolename",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_upms_role_sgr_orgid",
                table: "upms_role",
                column: "sgr_orgid");

            migrationBuilder.CreateIndex(
                name: "IX_upms_role_resource_m_resourcecode",
                table: "upms_role_resource",
                column: "m_resourcecode");

            migrationBuilder.CreateIndex(
                name: "IX_upms_role_resource_m_roleid",
                table: "upms_role_resource",
                column: "m_roleid");

            migrationBuilder.CreateIndex(
                name: "IX_upms_temporary_tokens_Code",
                table: "upms_temporary_tokens",
                column: "Code",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_upms_user_sgr_orgid",
                table: "upms_user",
                column: "sgr_orgid");

            migrationBuilder.CreateIndex(
                name: "UK_User_LoginName",
                table: "upms_user",
                column: "m_loginname",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "UK_User_UserEmail",
                table: "upms_user",
                column: "m_useremail",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "UK_User_UserPhone",
                table: "upms_user",
                column: "m_userphone",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "UK_User_WeChatOpenId",
                table: "upms_user",
                column: "m_wechatopenid",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "UK_User_WeChatUnionId",
                table: "upms_user",
                column: "m_wechatunionid",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_upms_user_duty_m_dutyid",
                table: "upms_user_duty",
                column: "m_dutyid");

            migrationBuilder.CreateIndex(
                name: "IX_upms_user_duty_m_userid",
                table: "upms_user_duty",
                column: "m_userid");

            migrationBuilder.CreateIndex(
                name: "IX_upms_user_refreshtoken_m_expires",
                table: "upms_user_refreshtoken",
                column: "m_expires");

            migrationBuilder.CreateIndex(
                name: "IX_upms_user_refreshtoken_m_token",
                table: "upms_user_refreshtoken",
                column: "m_token");

            migrationBuilder.CreateIndex(
                name: "IX_upms_user_role_m_userid_m_roleid",
                table: "upms_user_role",
                columns: new[] { "m_userid", "m_roleid" },
                unique: true);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "upms_department");

            migrationBuilder.DropTable(
                name: "upms_duty");

            migrationBuilder.DropTable(
                name: "upms_loglogin");

            migrationBuilder.DropTable(
                name: "upms_menus");

            migrationBuilder.DropTable(
                name: "upms_org_invitations");

            migrationBuilder.DropTable(
                name: "upms_organization");

            migrationBuilder.DropTable(
                name: "upms_role_resource");

            migrationBuilder.DropTable(
                name: "upms_temporary_tokens");

            migrationBuilder.DropTable(
                name: "upms_user_duty");

            migrationBuilder.DropTable(
                name: "upms_user_refreshtoken");

            migrationBuilder.DropTable(
                name: "upms_user_role");

            migrationBuilder.DropTable(
                name: "upms_role");

            migrationBuilder.DropTable(
                name: "upms_user");
        }
    }
}
